import { useUserStore } from '~/stores/user'
import { useAppStore } from '~/stores/app'

export default {
  data() {
    return {
      location: {},
      test: '测试测试',
      CityName: '',
    }
  },
  onLoad() {
    uni.hideTabBar()
    this.CityName = uni.getStorageSync('City_Name') || ''
    // 获取当前页面路径
    const pages = getCurrentPages()
    console.log('pages', pages)

    // if (!this.userInfo) {
    //   uni.switchTab({
    //     url: '/pages/tabbar/my/index',
    //   })
    // }
  },
  computed: {
    userInfo() {
      return useUserStore().userInfo
    },
    userLocation() {
      return useUserStore().location
    },
    appConfig() {
      return useAppStore().config
    },
  },
  mounted() {
  },
  methods: {
    checkLogin() {
      if (!this.userInfo) {
        uni.switchTab({
          url: '/pages/tabbar/my/index',
        })
        return false
      }
      return true
    },
    // 跳转页面
    jump(url, type = 'to') {
      if (type === 'tabbar')
        uni.switchTab({ url })
      else if (type === 'to')
        uni.navigateTo({ url })
    },

    getMyLocation() {
      tt.getLocation({
        success: (res) => {
          this.location = res
          console.log(res)
          useUserStore().location = res
        },
        fail(res) {
          console.log('调用失败', res)
        },
      })
    },
  },
}
